<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>智能化停车场管理系统-登陆</title>
    <link rel="stylesheet" href="/static/assets/css/layui.css">
    <link rel="stylesheet" href="/static/assets/css/admin.css">
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <style>
        html, body {width: 100%;height: 100%;overflow: hidden}
        body {background: #1E9FFF;}
        body:after {content:'';background-repeat:no-repeat;background-size:cover;-webkit-filter:blur(3px);-moz-filter:blur(3px);-o-filter:blur(3px);-ms-filter:blur(3px);filter:blur(3px);position:absolute;top:0;left:0;right:0;bottom:0;z-index:-1;}
        .layui-container {width: 100%;height: 100%;overflow: hidden}
        .admin-login-background {width:360px;height:300px;position:absolute;left:50%;top:40%;margin-left:-180px;margin-top:-100px;}
        .logo-title {text-align:center;letter-spacing:2px;padding:14px 0;}
        .logo-title h1 {color:#1E9FFF;font-size:25px;font-weight:bold;}
        .login-form {background-color:#fff;border:1px solid #fff;border-radius:3px;padding:14px 20px;box-shadow:0 0 8px #eeeeee;}
        .login-form .layui-form-item {position:relative;}
        .login-form .layui-form-item label {position:absolute;left:1px;top:1px;width:38px;line-height:36px;text-align:center;color:#d2d2d2;}
        .login-form .layui-form-item input {padding-left:36px;}
        .captcha {width:60%;display:inline-block;}
        .captcha-img {display:inline-block;width:34%;float:right;}
        .captcha-img img {height:34px;border:1px solid #e6e6e6;height:36px;width:100%;}
    </style>
</head>
<body>
<div class="layui-container">
    <div class="admin-login-background">
        <div class="layui-form login-form">
            <div class="layui-form-item logo-title">
                <h1>智能化停车场登录</h1>
            </div>
            <div class="layui-form-item">
                <label class="layui-icon layui-icon-username" for="username"></label>
                <input type="text" id="userName" name="username" lay-verify="required|account" placeholder="用户名或者邮箱" autocomplete="off" class="layui-input" value="admin">
            </div>
            <div class="layui-form-item">
                <label class="layui-icon layui-icon-password" for="password"></label>
                <input type="password" id="userPwd" name="password" lay-verify="required|password" placeholder="密码" autocomplete="off" class="layui-input" value="123456">
            </div>
            <div class="layui-form-item">
                <label class="layui-icon layui-icon-vercode" for="captcha"></label>
                <input type="text" name="captcha" id="checkCode" lay-verify="required|captcha" placeholder="图形验证码" autocomplete="off" class="layui-input verification captcha" value="xszg">
                <div class="captcha-img">
                    <img id="captchaPic" src="/user/checkCode">
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn layui-btn-normal layui-btn-fluid" lay-submit="" id="login" lay-filter="login">登 入</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script src="/static/assets/jquery.min.js"></script>
<script src="/static/assets/layui.all.js"></script>
<script src="/static/assets/md5.js"></script>
<script src="/static/assets/jquery.particleground.min.js"></script>
<script>
    $(function() {
        layui.use('layer', function() {
            var layer = layui.layer;

            // 粒子线条背景
            $(document).ready(function(){
                $('.layui-container').particleground({
                    dotColor:'#7ec7fd',
                    lineColor:'#7ec7fd'
                });
            });

            function login(){
                console.log("登录请求");
                var userName=$("#userName").val()
                var userPwd=$("#userPwd").val()
                var pwd =hex_md5(userPwd)
                var code=$("#checkCode").val()
                if(userName===""&&userPwd===""){
                    layer.msg("请输入用户名和密码")
                }else if(code===""){
                    layer.msg("请输入验证码")
                }else {
                    $.ajax({
                        url:"/user/login",
                        type:"post",
                        headers:{'Content-Type':'application/json;charset=utf8'},
                        data:JSON.stringify({"userName":userName,"userPwd":pwd,"code":code}),
                        dataType:"json",
                        success:function (data) {
                            if(200===data.code){
                                $("#login").attr("disabled","disable")
                                $("#userPwd").val(pwd)
                                layer.msg("登录成功")
                                sessionStorage.setItem("roleId",data.data.roleId);
                                sessionStorage.setItem("userId",data.data.userId);
                                setTimeout('location.href="/desk/main"',2000);
                            }else if (404===data.code) {
                                layer.msg(data.message)
                                $("#captchaPic").attr("src","/user/checkCode?name="+new Date().getTime())
                            }else if (0===data.code){
                                layer.msg("用户名或者密码错误")
                                $("#captchaPic").attr("src","/user/checkCode?name="+new Date().getTime())
                            }else if(808===data.code){
                                layer.msg(data.message)
                                $("#captchaPic").attr("src","/user/checkCode?name="+new Date().getTime())
                            }
                        },
                        error:function () {
                            console.log("请求失败")
                        }
                    })
                }
            }
            $("#login").on("click",function () {
                login()
            })
            $("#captchaPic").on("click",function () {
                $("#captchaPic").attr("src","/user/checkCode?name="+new Date().getTime())
            })
        })
    })

</script>